home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_200
/
235_01
/
ovfile.c
< prev
next >
Wrap
Text File
|
1987-06-16
|
25KB
|
763 lines
/* 061 14-Feb-87 ovfile.c
Copyright (c) 1987 by Blue Sky Software. All rights reserved.
*/
#include <stdio.h>
#include <dos.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "ov.h"
#include "dosfile.h"
static int stowidx;
static FILE_ENT *stowfp;
static DRIVE_ENT *drvlst = NULL;
static char *none_tagged = "There are NO tagged files.";
static char *notitself = "You can't copy a file to itself!";
static char *mustbedir = "You must enter a drive and/or directory name!";
extern WINDOW cw;
extern int diridx;
extern char **dirlst;
extern FILE_ENT files[];
extern char *nullname, *cantopen;
DRIVE_ENT *findrive(int);
struct search_block *nxtfile();
char far *largest_f(unsigned int, unsigned int *);
char *strupr(), *strchr(), *dirplus(FILE_ENT *, char *);
char *parsepath(char *, char *, char *, int, char **, char **);
int free_f(char far *), stowfile(struct search_block *, char *);
int readbuf(int,char far *,unsigned int), writebuf(int,char far *,unsigned int);
int add2windows(char *, char *, FILE_ENT *), delfromwins(char *, char *);
/******************************************************************************
** G E T F I L E S **
*****************************************************************************/
getfiles() { /* get data for the files in the current dir */
int firsttime;
char pathbuf[MAX_PATHLEN+6];
register struct search_block *sbp;
cw.files_size = 0; /* no files yet */
firsttime = TRUE; /* tell nxtfile() its the first call */
stowidx = 0; /* start storing at the begining */
stowfp = files;
/* if showall mode is active, call scantree to get all files, otherwise
scan the current dir ourselves */
if (cw.showall) { /* scan the current disk? */
*pathbuf = '\0';
strncat(pathbuf,cw.dirbuf,2);
scantree("\\",pathbuf,0x16,stowfile); /* scan entire disk */
} else /* scan the current directory */
while (stowidx < MAX_FILES && (sbp = nxtfile("*.*",0x16,&firsttime)))
stowfile(sbp,NULL);
/* sort the file names if there are any, also set nfiles */
if (cw.nfiles = stowidx)
sort_files(NULL);
/* set current file pointer to the first file */
cw.curidx = 0;
/* set file counters */
cw.num_files = cw.nfiles; /* files in the dir */
cw.num_tagged = 0; /* no files tagged yet */
cw.tag_size = 0;
}
/*****************************************************************************
S T O W F I L E
*****************************************************************************/
static int
stowfile(sbp,dirp) /* store a file in files[] */
register struct search_block *sbp;
char *dirp;
{
register int len;
static char *lastdir = NULL;
register FILE_ENT *fp = stowfp; /* fast stow pointer */
/* if dirp is not NULL, this call is defining which dir is being scanned,
add this dir name to the showall dir list - return NZ (keep going) if
dir name added okay, 0 (stop scanning) if can't add dir name - don't
incr diridx unless everything is okay. The dir name passed will always
have a trailing \ which we don't really want - don't keep it unless
this happens to be the root dir (len == 3) */
if (dirp) {
if (diridx < MAX_DIR) {
len = strlen(dirp);
dirlst[diridx++] = lastdir = Strndup(dirp,len > 3 ? len-1 : len);
return(1);
}
return(0);
}
/* ignore . and .. entries. If the file mask is defined, make
sure the file name matches. Make sure the file attributes
match the selection attributes */
if (stowidx >= MAX_FILES || *sbp->fn == '.' ||
(cw.selatrs & sbp->attrib) != sbp->attrib ||
(*cw.mask && (cw.maskcmp != match_name(sbp->fn,cw.mask))))
return(1); /* don't want this one, but keep looking */
/* we want the file, fill in files[] entry */
fp->size = sbp->size;
fp->flags = sbp->attrib & 0x3f;
fp->index = stowidx++;
fp->date = sbp->date;
fp->time = sbp->time;
strcpy(fp->name,sbp->fn);
fp->dirp = cw.showall ? lastdir : cw.dirbuf; /* point to files dir str */
cw.files_size += fp->size; /* accumulate total size */
stowfp++; /* update for next time */
return(1); /* keep looking */
}
/******************************************************************************
** I N F O **
*****************************************************************************/
info() { /* toggle the extended info display */
cw.info_display ^= 1; /* toggle info on/off */
infocnt(cw.info_display ? 1 : -1); /* one more or less info window */
adjust_window(); /* resize the window data */
update_window(1); /* display files in new format */
}
/******************************************************************************
R E N _ C U R
******************************************************************************/
ren_cur() { /* rename (or move) the current file */
int rc;
register FILE_ENT *fp;
char *newname, fn[MAX_NAMELEN+1];
static char ptxt[] = "Enter new file name or directory name for ";
char *fnp, *target, *todir, *tofn, *dirp, pmsg[sizeof(ptxt)+MAX_NAMELEN+1];
fp = &files[cw.curidx];
strcpy(pmsg,ptxt); /* build prompt string */
strcat(pmsg,strcpy(fn,fp->name));
newname = strupr(prompt("Rename current file",pmsg,NULL,0,MAX_REPLY));
if (strlen(newname) == 0)
return;
/* figure out the full target name, the dir, and the fn */
rc = isadir(dirp=fp->dirp,newname); /* need to know if this is a dir name */
target = parsepath(dirp,fn,newname,rc,&todir,&tofn);
fnp = fname(fp); /* from name */
rc = rename(fnp,target); /* rename/move it */
if (rc == 0) { /* rename okay? */
/* note: fn is a local array instead of a pointer to fp->name because
add2windows() may shift the entries in files[] around thereby making
fp->name point to the wrong file - same goes for local dirp */
add2windows(todir,tofn,fp); /* add to new window(s) */
delfromwins(dirp,fn); /* del from old window(s) */
} else /* unable to rename */
show_error(1,0,3,"Unable to rename ",fn,": ");
free(target); /* release temp strings */
free(todir);
free(tofn);
free(fnp);
}
/******************************************************************************
R E N _ T A G
******************************************************************************/
ren_tag() { /* rename (move) all tagged files to another dir */
int i, rc;
register FILE_ENT *fp;
char *newdir, *fnp, *target, *todir, *dirp, fn[MAX_NAMELEN+1];
if (cw.num_tagged == 0) /* are there any tagged files? */
show_error(0,14,1,none_tagged);
newdir = strupr(prompt("Move tagged files","Enter new directory name",
NULL,0,MAX_REPLY));
if (strlen(newdir) == 0)
return;
/* the name given must be a directory name */
if (!isadir(cw.dirbuf,newdir))
show_error(0,12,1,mustbedir);
/* Okay, move the tagged files */
for (i = 0, fp = files; i < cw.nfiles && !brkout(); i++, fp++)
if (fp->flags & TAGGED) { /* this file tagged? */
/* figure out the target names */
dirp = fp->dirp;
target = parsepath(dirp,strcpy(fn,fp->name),newdir,1,&todir,NULL);
fnp = fname(fp);